﻿using log4net;
using log4net.Config;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Rapid.Utility.Helper
{
    /// <summary>
    /// 日志记录工具 
    /// </summary>
    public static class LogHelper
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        static LogHelper()
        {
            XmlConfigurator.ConfigureAndWatch(new FileInfo(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"\log4net.config"));
        }

        /// <summary>
        /// 记录Info日志
        /// </summary>
        /// <param name="msg">消息</param>
        public static void Info(string msg)
        {
            LogManager.GetLogger("系统消息").Info(msg);
        }

        /// <summary>
        /// 记录Info日志
        /// </summary>
        /// <param name="obj">某个类对象</param>
        /// <param name="msg">消息</param>
        public static void Info(object obj, string msg)
        {
            LogManager.GetLogger(obj.GetType()).Info(msg);
        }

        /// <summary>
        /// 记录Error日志
        /// </summary>
        /// <param name="ex">异常</param>
        public static void Error(Exception ex)
        {
            LogManager.GetLogger(ex.Source).Error(ex.Message, ex);
        }

        /// <summary>
        /// 记录Error日志
        /// </summary>
        /// <param name="ex">异常</param>
        /// <param name="msg">消息</param>
        public static void Error(Exception ex, string msg)
        {
            LogManager.GetLogger(ex.Source).Error(msg, ex);
        }

        /// <summary>
        /// 记录Error日志
        /// </summary>
        /// <param name="obj">某个类对象</param>
        /// <param name="ex">异常</param>
        public static void Error(object obj, Exception ex)
        {
            LogManager.GetLogger(obj.GetType()).Error(ex.Message, ex);
        }

        /// <summary>
        /// 记录Error日志
        /// </summary>
        /// <param name="obj">某个类对象</param>
        /// <param name="ex">异常</param>
        /// <param name="msg">消息</param>
        public static void Error(object obj, Exception ex, string msg)
        {
            LogManager.GetLogger(obj.GetType()).Error(msg, ex);
        }
    }
}